﻿@using Framework.HtmlHelpers
@using WebUI.Areas.Admin.Models.Common
@using WebUI.Extensions
@using Domain
@model IList<NormTarget>
@{
	Layout = "~/Areas/Admin/Views/Shared/_AdminContent.cshtml";
	EmployeeInfo evaedEmployee = ViewBag.EvaedEmployee;
	NormType normType = ViewBag.NormType;
	int evaTaskId = ViewBag.EvaTaskId;
	string redirectUrl = TempData["RedirectUrl"].ToString();
	int questionCount = Model.Where(m => (m.ChildTargetList == null || m.ChildTargetList.Count <= 0) && (m.OptionsList != null && m.OptionsList.Count >= 1)).Count();
}
@section head {
	<link href="~/dist/AdminLTE/plugins/iCheck/all.css" rel="stylesheet" />
}
@section body {
	<script src="~/dist/AdminLTE/plugins/iCheck/icheck.min.js"></script>
	<script>

		function showMessage(message, type) {
			$("#js-message").fadeIn();
			switch (type) {
				case -1:
					$("#js-message").attr("class", "alert alert-danger").find(".message").html(message);
					break;
				case 1:
					$("#js-message").attr("class", "alert alert-success").find(".message").html(message);
					break;
			}
			// 3s 后隐藏
			setTimeout(function () {
				$("#js-message").fadeOut("slow");
			}, 3000);
		}

		function saveData() {
			$.ajax({
				url: "/Admin/TeacherEva/Eva",
				type: "post",
				dataType: "json",
				data: $("#js-form input").serialize(),
				success: onSuccess
			});
		}

		function onSuccess(data) {
			if (data.code <= 0) {
				showMessage(data.message, -1);
			} else {
				window.location.href = '/Admin/TeacherEva/EvaSuccess?redirectUrl=' + '@redirectUrl';
			}
		}

		$(function () {
			//iCheck for checkbox and radio inputs
			$('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
				checkboxClass: 'icheckbox_minimal-blue',
				radioClass: 'iradio_minimal-blue'
			});

			$('input[type="radio"]').on('ifChecked', function () {
				var completeCount = $('input[type="radio"]:checked').length;
				$('[area="js-completeCount"]').html(completeCount);
				var percent = completeCount / @questionCount * 100;
				$('[area="js-progress"] div').css('width', percent + "%");
			});
		});
	</script>
}

<!-- start .box -->
<div class="box">
	<!-- start .box-header -->
	<div class="box-header">
		<h3 class="box-title col-sm-12">
			<span class="col-xs-3">被评人: @evaedEmployee.Name（@evaedEmployee.EmployeeCode）</span>
			<span class="col-xs-3">职位: @evaedEmployee.EmployeeDuty.Name</span>
			<span class="col-xs-3">
				@(evaedEmployee.Department?.DescDept() ?? "")
			</span>
			<span class="col-xs-3">评价类型: @normType.Name</span>
		</h3>
		<div class="col-xs-12" style="padding-top: 20px;">
			<p>共 @questionCount 题, 已完成<span area="js-completeCount">0</span> 题</p>
			<div area="js-progress" class="progress">
				<div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div>
			</div>
		</div>
	</div>
	<!-- end .box-header -->
	<!-- start .box-body -->
	<div class="box-body no-padding">
		<div id="js-form" class="panel-group" role="tablist" aria-multiselectable="true">
			@Html.Hidden("teacherId", evaedEmployee.ID)
			@Html.Hidden("evaTaskId", evaTaskId)
			@foreach (var item in Model)
			{
				<div class="panel panel-default">
					<div id="heading-@item.ID" class="panel-heading" role="tab">
						<h4 class="panel-title">
							<a role="button" data-toggle="collapse" href="#collapse-@item.ID" aria-expanded="true">
								@{
									// 指标链生成 eg: 学生方面 - 概念的讲解
									string title = "";
									NormTarget currentItem = item;
									while (currentItem != null)
									{
										title = currentItem.Name + " - " + title;
										currentItem = currentItem.ParentTarget;
									}
								}
								@title.Remove(title.Length - 3)
							</a>
						</h4>
					</div>
					<div id="collapse-@item.ID" class="panel-collapse collapse in" role="tabpanel">
						<div class="panel-body">
							<div class="form-group">
								@{ var optionSortedList = item.OptionsList.OrderBy(m => m.SortCode); }
								@foreach (var option in optionSortedList)
								{
									<div class="radio">
										<label>
											<input class="minimal" type="radio" name="normTarget_@item.ID" value="@option.ID">
											@option.Content
										</label>
										<span class="pull-right"><i class="fa fa-heart text-primary"></i> @option.Score</span>
									</div>
								}
							</div>
						</div>
					</div>
				</div>
			}
		</div>
	</div>
	<!-- end .box-body -->
	<!-- start .box-footer -->
	<div class="box-footer clearfix">
		<!-- start 提示框 -->
		@{ Html.RenderPartial("_MessagePartial"); }
		<!-- end 提示框 -->
		<div class="col-xs-12" style="padding-top: 20px;">
			<p>共 @questionCount 题, 已完成<span area="js-completeCount">0</span> 题</p>
			<div area="js-progress" class="progress">
				<div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div>
			</div>
		</div>
		<div class="btn-group col-md-4 col-md-offset-4 col-xs-12">
			<button class="btn btn-primary btn-lg btn-block" onclick="saveData()">提交</button>
			@if (redirectUrl != null)
			{
				<a class="btn btn-default btn-lg btn-block" href="@redirectUrl">返回</a>
			}
			else
			{
				<a class="btn btn-default btn-lg btn-block" href="javascript:history.go(-1);">返回</a>
			}
		</div>
	</div>
	<!-- end .box-footer -->
</div>
<!-- end .box -->
